/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package technotheist.geo.map.scalar;

import java.nio.ByteBuffer;
import java.nio.ShortBuffer;
import technotheist.geo.map.AIntMap;
import technotheist.geo.map.Format;

/**
 *
 * @author Mitchel Strachan
 */
public class ShortMap extends AIntMap<ShortBuffer> {

    final ShortBuffer data;

    public ShortMap(int sideLength, boolean normalized) {
        this(sideLength, 1, normalized);
    }

    public ShortMap(int sideLength, int components, boolean normalized) {
        super(sideLength, components, Format.Short, normalized);
        this.data = ByteBuffer.allocateDirect(byteCount).asShortBuffer();
    }

    public void set(int p, int u, int v, short value) {
        setInt(p, u, v, value);
    }

    public void set(int p, int u, int v, int component, short value) {
        setInt(index(p, u, v) + component, value);
    }

    @Override
    protected ShortBuffer data() {
        return data;
    }

    @Override
    public int getInt(int bufferIndex) {
        return data.get(bufferIndex);
    }

    @Override
    public void setInt(int bufferIndex, int value) {
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            throw new IllegalArgumentException("value must be between " + Short.MIN_VALUE + " and " + Short.MAX_VALUE);
        }
        data.put(bufferIndex, (byte) value);
    }
}
